/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Lenovo
 * Date: 2025-03-15
 * Time: 9:28
 */
public class Student {
    // 实例字段
    private String name;
    private int age;

    // 构造方法 1：无参构造方法
    public Student() {
        this.name = "张三";
        this.age = 18;
    }

    // 构造方法 2：带参构造方法
    public Student(String name, int age) {
        this.name = name;
        this.age = age;
    }

    // 实例方法：显示学生信息
    public void displayInfo() {
        System.out.println("Name: " + this.name);
        System.out.println("Age: " + this.age);
    }

    //调用构造方法
    public static void main(String[] args) {
        // 使用无参构造方法创建对象
        Student student1 = new Student();
        student1.displayInfo(); // 输出: Name: 张三, Age: 18

        // 使用带参构造方法创建对象
        Student student2 = new Student("Alice", 20);
        student2.displayInfo(); // 输出: Name: Alice, Age: 20
    }
}